package com.example.demo.config;

import lombok.Data;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;

//@Data
//@Configuration
//@ConfigurationProperties(prefix = "elasticsearch")
//public class ElasticSearchConfig extends AbstractElasticsearchConfiguration {
//
//    private String host;
//    private Integer port;
//    @Value("${spring.elasticsearch.rest.password}")
//    private String password;
//    @Value("${spring.elasticsearch.rest.username}")
//    private String username;
//
//    @Override
//    public RestHighLevelClient elasticsearchClient() {
//        final CredentialsProvider provider = new BasicCredentialsProvider();
//        provider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
//        RestClientBuilder restClientBuilder = RestClient.builder(new HttpHost("192.168.70.27", 9200, "http"))
//                .setHttpClientConfigCallback(f -> f.setDefaultCredentialsProvider(provider));
//        return new RestHighLevelClient(restClientBuilder);
//    }
//
//
//}